﻿@model Tau.ViewModels.PublicProductSearchResults

@{
    Layout = "~/Views/Shared/_LayoutPublic.cshtml";
    ViewBag.Title = "Product Search Results";
}

@Html.Partial("ProductSearch", Model.ProductSearch)

<table width="98%" border="0" cellspacing="0" cellpadding="0">
    @if (Model.NumberOfPages > 1)
    {
        <tr>
            <td>Search results</td>
            <td align="right">
                @using (Html.BeginForm("Search", "Product", FormMethod.Post, new { id = "paging" }))
                {
                    @Html.HiddenFor(m => m.ProductSearch.SearchString)

                    <text>goto page:</text>
                    <select id="ProductSearch_PageNumber" name="ProductSearch.PageNumber" onchange="submitPaging();">
                        @for (int i = 1; i <= Model.NumberOfPages; i++)
                        {
                            string selected = i == Model.ProductSearch.PageNumber ? "selected" : string.Empty;
                            <option @selected value="@i">@i.ToString()</option>
                        }
                    </select>
                    <text>of</text> @Html.DisplayTextFor(m => m.NumberOfPages)
                }
            </td>
        </tr>
    }
    <tr>
        <td colspan="2">
            <hr />
        </td>
    </tr>

    @if (Model.Products != null)
    {
        foreach (var product in Model.Products)
        {
        <tr>
            <td>
                <table style="font-size:small" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td align="center" valign="middle" style="padding-left:5px; padding-right:5px; height:140px">
                            <a href='@Url.Action("GetProduct", "Product", new { id = product.ProductId })'>
                                <img src="@Url.Action("GetImage", "Image", new { id = product.ImageId, type = "thumbnail", area = "" })" />
                            </a>   
                        </td>    
                    </tr>
                </table>
            </td>
            <td>
                <table>
                    <tr>
                        <td>
                            Item name:
                        </td>
                        <td>
                            @product.ProductName
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Item number:
                        </td>
                        <td>
                            @product.ProductNumber
                        </td>
                    </tr>
                     <tr>
                        <td>
                            Price:
                        </td>
                        <td>
                            @string.Format("{0:C}", product.Price)
                        </td>
                    </tr>
                     <tr>
                        <td>
                            Shipping:
                        </td>
                        <td>
                            @string.Format("{0:C}", product.ShippingCost)
                        </td>
                    </tr>
                     <tr>
                        <td style="height:10px">
                        </td>
                    </tr>
                     <tr>
                        <td valign="top">
                            Description:
                        </td>
                        <td>
                            @product.ShortDescription<br />
                            <a href='@Url.Action("GetProduct", "Product", new { id = product.ProductId })'>View Full Details</a>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                 <hr />
            </td>
        </tr>
        
        }
    }
    
    @if (Model.NumberOfPages > 1)
    {
        <tr>
            <td colspan="2" align="right">
                @using (Html.BeginForm("Search", "Product", FormMethod.Post, new { id = "paging" }))
                {
                    @Html.HiddenFor(m => m.ProductSearch.SearchString)

                    <text>goto page:</text>
                    <select id="ProductSearch_PageNumber" name="ProductSearch.PageNumber" onchange="submitPaging();">
                        @for (int i = 1; i <= Model.NumberOfPages; i++)
                        {
                            string selected = i == Model.ProductSearch.PageNumber ? "selected" : string.Empty;
                            <option @selected value="@i">@i.ToString()</option>
                        }
                    </select>
                    <text>of</text> @Html.DisplayTextFor(m => m.NumberOfPages)
                }
            </td>
        </tr>
    }
</table>

<script type="text/javascript" language="javascript">
    function submitPaging() {
        $("#paging").submit();
    }
</script>